﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CustomControlDatabaseInterface.Utilities
{
    static class ViewModelUtil 
    {
        public static ObservableCollection<String> ConvertToObservableCollection(List<String> list)
        {
            ObservableCollection<String> result = new ObservableCollection<String>();
            foreach (var item in list)
            {
                result.Add(item);
            }
            return result;
        }

        public static void UpdateObservableCollection(ObservableCollection<String> oldList, List<String> newList)
        {
            List<String> AddList = new List<string>();
            List<String> RemoveList = new List<string>();
            foreach (String item in oldList)
            {
                if (oldList.Contains(item) && !newList.Contains(item)) RemoveList.Add(item);
            }
            foreach (String item in newList)
            {
                if (newList.Contains(item) && !oldList.Contains(item)) AddList.Add(item);

            }
            foreach (String item in RemoveList)
            {
                oldList.Remove(item);
            }
            foreach (String item in AddList)
            {
                oldList.Add(item);
            }
        }

    }
}
